package com.kavinz.algo.string.other;

/**
 * 《Cracking the coding interview》- #Interview Questions 
 * 1.2 Write code to reverse a C-Style String (C-String means that “abcd” is represented as five
 * characters, including the null character )
 * 
 * Note:I use '*' to represent null character
 * 
 * @author Kevin Zhao
 * 
 */
public class CStyleString {

	static char nullCharacter = '*';//I use '*' to represent null character
	public static String reverse(String input)
	{
		int length = input.length();
		String strWithoutNull = input.substring(0,length-1);
		StringBuilder reversedStr = new StringBuilder();
		for(int i =length-2 ;i>=0;i--)
		{
			reversedStr.append(strWithoutNull.charAt(i));
		}
		reversedStr.append(nullCharacter);
		
		return reversedStr.toString();
	}
	public static void main(String[] args) {
		String test1 = "adasb*";
		System.out.println(CStyleString.reverse(test1));
	}
}
